import 'package:json_annotation/json_annotation.dart';
import 'package:yt_devops/utils/enums.dart';

class SiteElecPriceSettingModel {

  ///规则id，示例：1
  int? id;

  ///规则名称，示例：规则一
  String? name;

  ///站点id，示例：1
  int? siteId;

  ///状态，状态  0未生效 1已生效
  int? status;

  ///操作人，示例：系统管理员
  String? operator;

  ///最后操作时间，示例：2023-06-28 09:34:17
  String? lastOperationTime;

  ///规则生效时间集合，示例：-
  List<EffectiveTimeList>? effectiveTimeList;

  ///需量电价/容量电费，示例：0.7
  String? demandElectrovalency;

  ///电费类型 0需量电费  1容量电费
  int? electricityType;

  ///平电价，示例：0.675069
  String? flatPrice;

  ///最大需量/变压器容量，示例：0.7
  String? maxDemand;

  ///峰电价，示例：1.02757
  String? peakPrice;

  ///功率因数，示例：0.4
  String? powerFactor;

  ///尖电价，示例：0
  String? sharpPrice;

  ///谷电价，示例：0.231069
  String? valleyPrice;

  ///电价时段集合，示例：-
  List<HoursPriceList>? hoursPriceList;

  SiteElecPriceSettingModel({
    this.demandElectrovalency,
    this.effectiveTimeList,
    this.electricityType,
    this.flatPrice,
    this.id,
    this.lastOperationTime,
    this.maxDemand,
    this.name,
    this.operator,
    this.peakPrice,
    this.powerFactor,
    this.sharpPrice,
    this.siteId,
    this.status,
    this.valleyPrice,
    this.hoursPriceList,
  });

  factory SiteElecPriceSettingModel.fromJson(Map<String, dynamic> json) => SiteElecPriceSettingModel(
    demandElectrovalency: json["demandElectrovalency"] ?? '',
    effectiveTimeList: json["effectiveTimeList"] != null
        ? List<EffectiveTimeList>.from(json["effectiveTimeList"].map((e) => EffectiveTimeList.fromJson(e)))
        : [],
    electricityType: json["electricityType"] ?? 0,
    flatPrice: json["flatPrice"] ?? '',
    id: json["id"] ?? '',
    lastOperationTime: json["lastOperationTime"] ?? '',
    maxDemand: json["maxDemand"] ?? '',
    name: json["name"] ?? '',
    operator: json["operator"] ?? '',
    peakPrice: json["peakPrice"] ?? '',
    powerFactor: json["powerFactor"] ?? '',
    sharpPrice: json["sharpPrice"] ?? '',
    siteId: json["siteId"] ?? 0,
    status: json["status"] ?? 0,
    valleyPrice: json["valleyPrice"] ?? '',
    hoursPriceList: json["hoursPriceList"] != null
        ? List<HoursPriceList>.from(json["hoursPriceList"].map((e) => HoursPriceList.fromJson(e)))
        : [],
  );

  Map<String, dynamic> toJson() => {
    "demandElectrovalency": demandElectrovalency,
    "effectiveTimeList": List<dynamic>.from(effectiveTimeList!.map((e) => e.toJson())),
    "electricityType": electricityType,
    "flatPrice": flatPrice,
    "id": id,
    "lastOperationTime": lastOperationTime,
    "maxDemand": maxDemand,
    "name": name,
    "operator": operator,
    "peakPrice": peakPrice,
    "powerFactor": powerFactor,
    "sharpPrice": sharpPrice,
    "siteId": siteId,
    "status": status,
    "valleyPrice": valleyPrice,
    "hoursPriceList": List<dynamic>.from(hoursPriceList!.map((e) => e.toJson())),
  };

}

class EffectiveTimeList {

  ///生效开始时间，示例：01-01
  String? effectiveTime;

  ///生效结束时间，示例：12-31
  String? expirationTime;

  ///规则生效时间id，示例：1
  int? id;

  /// 市电Id
  int? mainsId;

  /// 上网Id
  int? internetId;

  /// 充电Id
  int? chargeId;

  EffectiveTimeList({
    this.effectiveTime,
    this.expirationTime,
    this.id,
    this.mainsId,
    this.internetId,
    this.chargeId,
  });

  factory EffectiveTimeList.fromJson(Map<String, dynamic> json) => EffectiveTimeList(
    effectiveTime: json["effectiveTime"] ?? '',
    expirationTime: json["expirationTime"] ?? '',
    id: json["id"] ?? 0,
    mainsId: json["mainsId"] ?? 0,
    internetId: json["internetId"] ?? 0,
    chargeId: json["chargeId"] ?? 0,
  );

  Map<String, dynamic> toJson() => {
    "effectiveTime": effectiveTime,
    "expirationTime": expirationTime,
    "id": id,
    "mainsId": mainsId,
    "internetId": internetId,
    "chargeId": chargeId,
  };
}

class HoursPriceList {

  ///电价时段id，示例：1
  int? id;

  ///结束时间，示例：11:30
  String? intervalEndTime;

  ///开始时间，示例：09:00
  String? intervalStartTime;

  ///示例：1
  int? mainsId;

  ///0尖 1峰 2平 3谷
  int? type;
  ///放电电价0尖 1峰 2平 3谷
  int? elecType;
  /// 上网
  int? internetId;

  /// 电价
  String? electricityFees;

  /// 充电
  int? chargeId;

  /// 服务费，示例：0.41
  String? serviceFees;

  HoursPriceList({
    this.id,
    this.intervalEndTime,
    this.intervalStartTime,
    this.mainsId,
    this.type,
    this.elecType,
    this.internetId,
    this.electricityFees,
    this.chargeId,
    this.serviceFees,
  });

  factory HoursPriceList.fromJson(Map<String, dynamic> json) => HoursPriceList(
    id: json["id"] ?? 0,
    intervalEndTime: json["intervalEndTime"] ?? '',
    intervalStartTime: json["intervalStartTime"] ?? '',
    mainsId: json["mainsId"] ?? 0,
    type: json["type"] ?? 0,
    elecType: json["elecType"] ?? 0,
    internetId: json["internetId"] ?? 0,
    electricityFees: json["electricityFees"] ?? '',
    chargeId: json["chargeId"] ?? 0,
    serviceFees: json["serviceFees"] ?? '',
  );

  Map<String, dynamic> toJson() => {
    "id": id,
    "intervalEndTime": intervalEndTime,
    "intervalStartTime": intervalStartTime,
    "mainsId": mainsId,
    "type": type,
    "elecType":elecType,
    "internetId": internetId,
    "electricityFees": electricityFees,
    "chargeId": chargeId,
    "serviceFees": serviceFees,
  };
}

